## -*- coding: utf-8 -*-
<%inherit file="/index.mako" />
<%def name="title()">Home - Welcome</%def>
<%
	
	def message(messages):
		p = ""
		if messages:
			for message in messages:
				p = p + "<p>[%s] %s:%s<p>" % ( message.when_created, message.last_name, message.message)
		else:
			p = "<span id='no-message'>Aucun Messages</span>" 
		return str(p )	
%>

<div id="chat_window" OnUnload="alert('toto');">
	<p>Welcome on the Chat</p>
	<p style="font-size: 12px;">Personne(s) Connectée(s): <span id="chat_who_is_online"></span></p>
	<div id="chat_message_windows">
		<div id="chat_message_list">
			${message(c.messages) | n}
		</div>
		
		<form id="chat_submit_form" ">
			<input id="chat-message" type="text" name="message" size="200" />
			<input id="chat-send-message" type="submit" value="Envoyer" OnClick="return false;" />
		</form>
	</div>
	
</div>

<script type="text/javascript">

$(document).ready(function() {
	if($.browser.mozilla){
		$(window).unload(function() {
			
			i_am_leaving_chat(us_id);	  
		});
		$(window).load(function() {
			i_am_entering_chat(us_id);  
		})
		rezise_chat();
		check_who_is_online();
		scan_for_new_messages();
		chat_auto_scroll_down();
		$('#chat-message').focus();
		$('#chat-send-message').click(function(){
			var message = $('#chat-message').val();
			if($.trim(message) == ''){
				alert('Le message est vide !');
				return false;
			}else{
				add_new_messages(message, us_id);
				
			}
		});
	
	}else{
		alert('Chat disponible seulement pour Firefox');
		$('#chat_message_list').append('<span style="color: red; font-weight: bold; font-size: 18px;">Chat disponible seulement pour Firefox</span>');
	}
});
</script>